<script type="text/javascript">

$(document).ready(function(){
	jQuery(function() {
		$('.accessEnable a').livequery("click", function(){
			var currIndex = $('.accessEnable a').index($(this));
			var accessEnable = $($('.accessEnable').get(currIndex));

			var accessId = accessEnable.find("input[name='accessId']").val();
			//alert(accessId);
			$.ajax({
				type: "post",
				url: "<?php echo $this->url(array('module'=>'admin', 'controller'=>'acl', 'action'=>'changeaccessstate'), "default", true); ?>",
				data: {accessId:accessId},
				success: function(responseText, statusText)
				{
					//alert(responseText);
					var json = jQuery.parseJSON(responseText);
					if(json.result==1)
					{
						accessEnable.find("span").html(json.content);
					}
					
					if(json.message != '')
					{
						showDialog(json.message);
					}

					return "";
				},
				error: function(){
				}
			});
		});

		$('.roleAccess').find("input[name='now']").livequery("click", function(){
			var currIndex = $('.roleAccess').find("input[name='now']").index($(this));
			var roleAccess = $($('.roleAccess').get(currIndex));

			var actionId = roleAccess.find("input[name='actionId']").val();
			//alert(accessId);
			$.ajax({
				type: "post",
				url: "<?php echo $this->url(array('module'=>'admin', 'controller'=>'acl', 'action'=>'changeaccessapply'), "default", true); ?>",
				data: {actionId:actionId, roleId:'<?php echo $this->roleRow['role_id'];?>'},
				success: function(responseText, statusText)
				{
					//alert(responseText);
					var json = jQuery.parseJSON(responseText);
					if(json.result==1)
					{
						roleAccess.find(".accessState").html(json.content);
					}
					
					if(json.message != '')
					{
						showDialog(json.message);
					}

					return "";
				},
				error: function(){
				}
			});
		});
	});
});
</script>
<style type="text/css"> 
.roleAccess .columns 		{ border-bottom:solid 1px #666; padding:10px;}
.roleAccess .column1 		{ width:60px;}
.roleAccess .column2 		{ width:360px;}
</style>

<div><?php echo $this->roleRow['name'];?></div>

<?php if(is_array($this->actionAllArray)):?>
<?php foreach ($this->actionAllArray as $key=>$actionRow):?>
<div class="roleAccess">
	<div class="columns on-3">
		<div class="container"> 
			<div class="column fixed column1">
				<input type="hidden" name="actionId" value="<?php echo $actionRow['action_id'];?>"  />
				<div class="container"><input type="checkbox" name="now" value="1" <?php echo $actionRow['checked'];?> /></div> 
			</div> 
			<div class="column fixed column2"> 
				<div class="container"><?php echo $actionRow['name'];?></div> 
			</div> 
			<div class="column"> 
				<div class="container">
					<div class="accessState">
					<?php 
					echo $this->partial('module_admin_script_acl-role-access-row.phtml', array(
						    'actionRow' 			=> $actionRow,
						));
					?>
					</div>
				</div> 
			</div> 
		</div> 
	</div> 
</div>
<?php endforeach;?>
<?php endif;?>
